namespace Digitalmes.Application.Services.Impl;

/// <summary>
/// 系统配置 <see cref="SysConfig"/> 对象缓存。
/// </summary>
internal sealed class SysConfigQueryService(IRepository<SysConfig> configRepo) : ISysConfigQueryService
{
    public async Task<string?> GetValueAsync(string code)
    {
        var configs = await GetCacheListAsync();
        return configs.FirstOrDefault(s => s.Code == code)?.Value;
    }

    private async Task<IReadOnlyList<SysConfig>> GetCacheListAsync()
    {
        return await configRepo.AsQueryable()
                .Where(m => m.Status == EnabledStatusEnum.Enabled)
                .WithCache(CacheKeys.SysConfigKey)
                .ToListAsync();
    }
}
